package com.TT.ticket.threadPool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

public class TestDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //test2();
        test3();
    }


    public static void test2() throws ExecutionException, InterruptedException {
        long start = System.currentTimeMillis();


        ForkJoinPool forkJoinPool = new ForkJoinPool();
        ForkJoinTask<Long> forkJoinTask = new ForkJoinDemo(0L,10_0000_0000L);
        ForkJoinTask<Long> submit = forkJoinPool.submit(forkJoinTask);
        Long sum = submit.get();


        long end = System.currentTimeMillis();


        System.out.println("sum=" + sum + " 时间：" + (end-start)/1000);
    }


    public static void test3(){
        long start = System.currentTimeMillis();

        //流式并行
        long sum = LongStream.rangeClosed(0L, 10_0000_0000L).parallel().reduce(0, Long::sum);


        long end = System.currentTimeMillis();

        System.out.println("sum=" + sum + " 时间：" + (end-start));
    }
}
